package cn.bugstack.mybatis.io;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

public class Resources {

    public static Reader getResourceAsReader(String resource) throws IOException {
        ClassLoader[] classLoaders = {
                ClassLoader.getSystemClassLoader(),
                Thread.currentThread().getContextClassLoader()};
        for (ClassLoader classLoader : classLoaders) {
            InputStream resourceAsStream = classLoader.getResourceAsStream(resource);
            if (resourceAsStream != null) {
                return new InputStreamReader(resourceAsStream);
            }
        }
        throw new IOException("Could not find resource " + resource);
    }

    public static Class<?> classForName(String className) throws ClassNotFoundException {
        return Class.forName(className);
    }
}
